<template >
  <el-card class="box-card" >
    <el-form class="loginForm" >
      <h2>登录WebBlog</h2>
      <el-form-item>
        <el-input v-model="loginForm.userName" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          type="password"
          v-model="loginForm.password"
          placeholder="密码"
        ></el-input>
      </el-form-item>
     <!-- <el-checkbox v-model="checked" style="margin-bottom:20px">保持登录状态</el-checkbox> -->
        <el-button type="primary" @click="login" style="width: 100%"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        userName: "",
        password: "",
      },
      checked:true
    };
  },
  methods: {
    login() {
      if (this.loginForm.userName == "" || this.loginForm.password == "") {
        this.$message.error("请填写用户名和密码");
      } else {
        let formdata = new FormData();
        formdata.append("userName", this.loginForm.userName);
        formdata.append("password", this.loginForm.password);
        this.axios.post("/user/login", formdata).then((res) => {
          if (res.data.success) {
            localStorage.setItem("access-Token", res.data.token);
            localStorage.setItem("access-User", JSON.stringify(res.data.user));
            this.$message.success(res.data.msg);
            this.$router.push("./manage");
          } else {
            this.$message.error(res.data.msg);
          }
        });
      }
    }
  },
  
};
</script>

<style>
*{
  margin: 0;
  padding: 0;
}
.box-card {
  /* margin: 100px auto; */
  position:absolute;
  left: 50%;
  top:50%;
  transform: translate(-50%,-50%);
  width: 400px;
}
.loginForm h2{
  margin: 20px 0px;
}
.loginForm .el-form-item{
  margin: 30px 0px;
}
</style>